package yiliubabalongcaisuyun.com.longcai.longcaisuyun.testgrid;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import java.util.List;

/**
 * Created by Administrator on 2017/8/4.
 */

public class GridAdapter extends BaseAdapter {
    private Context context;
    private List<String> list;

    public GridAdapter(Context context, List<String> list) {
        this.context = context;
        this.list = list;
    }

    @Override
    public int getCount() {
        return list.size();
    }

    @Override
    public Object getItem(int i) {
        return list.get(i);
    }

    @Override
    public long getItemId(int i) {
        return 0;
    }

    @Override
    public View getView(int i, View convertView, ViewGroup viewGroup) {
        ViewHolder holder;
        if (convertView == null) {
            holder = new ViewHolder();
            convertView = LayoutInflater.from(context).inflate(R.layout.item2, null);
            holder.title = convertView.findViewById(R.id.id_num);
            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();

        }
        holder.title.setText(list.get(i));
        return convertView;
    }

    //在外面先定义，ViewHolder静态类
    static class ViewHolder {

        public TextView title;

    }
}
